<%@ Import Namespace="Portal" %>
<%@ Import Namespace="Portal.API" %>
<%@ Register TagPrefix="portal" Assembly="Portal.API" Namespace="Portal.API.Controls" %>
<%@ Control Language="c#" AutoEventWireup="true" Inherits="Portal.API.Module" TargetSchema="http://schemas.microsoft.com/intellisense/ie5"
	EnableViewState="false" %>

<script runat="server">
	private void Page_Load(object sender, System.EventArgs e)
	{
		account.Focus();

		// Some devices need a Submit button for the login.  
		if (Request.Browser.IsMobileDevice)
			lnkLogin.UseSubmitBehavior = true;
	}

	public override bool IsVisible()
	{
		return !Page.User.Identity.IsAuthenticated;
	}

	void OnLogin(object sender, EventArgs args)
	{
		if (UserManagement.Login(account.Text, password.Text))
		{
			if (m_AutoLogin.Checked)
			{
				HttpCookie cookie = new HttpCookie("PortalUser");
				cookie.Values["AC"] = Crypto.Encrypt(account.Text);
				cookie.Values["PW"] = Crypto.Encrypt(password.Text);
				DateTime dt = DateTime.Now;
				TimeSpan ts = new TimeSpan(100, 0, 0, 0);
				cookie.Expires = dt.Add(ts);
				Response.Cookies.Add(cookie);
			}
			Response.Redirect(Request.RawUrl);
		}
		else
		{
			lError.Text = Portal.API.Language.GetText(this, "InvalidLogin");
		}
	}
</script>

<asp:Panel ID="loginPanel" runat="server" DefaultButton="lnkLogin">
	<div>
		<asp:Label ID="lError" runat="server" CssClass="Error" />
	</div>
	<portal:Label ID="AccountLbl" runat="server" LanguageRef="Account" />
	<div>
		<asp:TextBox ID="account" runat="server" AutoCompleteType="DisplayName" />
	</div>
	<div>
		<portal:Label ID="PasswordLbl" runat="server" LanguageRef="Password" />
	</div>
	<div>
		<asp:TextBox ID="password" runat="server" TextMode="Password" />
	</div>
	<div>
		<asp:CheckBox ID="m_AutoLogin" runat="server" TextAlign="Left" />
		<portal:Label ID="Label1" runat="server" LanguageRef="AutoLogin" />
	</div>
	<div>
		<portal:Button ID="lnkLogin" runat="server" OnClick="OnLogin" LanguageRef="Login"
			CausesValidation="False" CssClass="loginButton" UseSubmitBehavior="False" />
	</div>
</asp:Panel>
